home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / ATL_Samples / sketch / sketcctl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  2.6 KB  |  133 lines

  1. // SketcCtl.cpp : Implementation of CSketcCtl
  2. #include "stdafx.h"
  3. #include "Sketch.h"
  4. #include "SketcCtl.h"
  5.  
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CSketcCtl
  8.  
  9. STDMETHODIMP CSketcCtl::InterfaceSupportsErrorInfo(REFIID riid)
  10. {
  11.     static const IID* arr[] = 
  12.     {
  13.         &IID_ISketcCtl,
  14.     };
  15.     for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  16.     {
  17.         if (InlineIsEqualGUID(*arr[i],riid))
  18.             return S_OK;
  19.     }
  20.     return S_FALSE;
  21. }
  22.  
  23.  
  24. STDMETHODIMP CSketcCtl::get_PenWidth(short *pVal)
  25. {
  26.     *pVal = m_PenWidth;
  27.     return S_OK;
  28. }
  29.  
  30. STDMETHODIMP CSketcCtl::put_PenWidth(short newVal)
  31. {
  32.     if (newVal > 0 && newVal < 7)
  33.     {
  34.         m_PenWidth = newVal;
  35.         return S_OK;
  36.     }
  37.  
  38.     else 
  39.             {
  40.         TCHAR szBuf1[80] = _T("");
  41.         int nResult = LoadString (_Module.m_hInst, IDS_ERROR, szBuf1, sizeof(szBuf1) );
  42.         return Error(szBuf1);
  43.     }
  44. }
  45.  
  46.  
  47. HRESULT CSketcCtl::OnDraw(ATL_DRAWINFO& di)
  48. {
  49.     RECT& rc = *(RECT*)di.prcBounds;
  50.     HBRUSH hBrush, hOldBrush;
  51.     hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
  52.     hOldBrush = (HBRUSH)SelectObject(di.hdcDraw, hBrush);
  53.  
  54.     left = rc.left;
  55.     top = rc.top;
  56.     right = rc.right;
  57.     bottom = rc.bottom;
  58.     Rectangle(di.hdcDraw, left, top, right, bottom);
  59.     SelectObject(di.hdcDraw, hOldBrush);
  60.  
  61.     return S_OK;
  62. }
  63.  
  64.  
  65. LRESULT CSketcCtl::OnLButtonDown(UINT uMsg, WPARAM wParam, 
  66.                                 LPARAM lParam, BOOL& bHandled) 
  67. {
  68.     HWND hWnd;
  69.     hWnd = ::SetCapture(m_hWnd);
  70.     bLBDown = TRUE;
  71.     line[0].x = LOWORD(lParam);
  72.     line[0].y = HIWORD(lParam);
  73.     return 0;
  74. }
  75.  
  76. LRESULT CSketcCtl::OnLButtonUp(UINT uMsg, WPARAM wParam, 
  77.                                 LPARAM lParam, BOOL& bHandled) 
  78. {
  79.     ReleaseCapture();
  80.     bLBDown = FALSE;
  81.     line[1].x = LOWORD(lParam);
  82.     line[1].y = HIWORD(lParam);
  83.     return 0;
  84. }
  85.  
  86.  
  87. LRESULT CSketcCtl::OnMouseMove(UINT uMsg, WPARAM wParam, 
  88.                                 LPARAM lParam, BOOL& bHandled) 
  89.     static BOOL bThere = FALSE;
  90.  
  91.     if ((::GetCapture() == m_hWnd) )
  92.     {
  93.         if (LOWORD(lParam) < 65000 && HIWORD(lParam) < 65000)
  94.         {
  95.             if (bThere)
  96.             {
  97.                 bThere = FALSE;
  98.                 line[0].x = LOWORD(lParam);
  99.                 line[0].y = HIWORD(lParam);
  100.             }
  101.             else
  102.             {
  103.                 line[1].x = LOWORD(lParam);
  104.                 line[1].y = HIWORD(lParam);
  105.                 if ( (line[0].x != line[1].x || line[0].y != line[1].y) )
  106.                 {
  107.                     HDC hdc = GetDC();
  108.                     SelectObject(hdc, CreatePen(PS_SOLID, (m_PenWidth - 1), 0));
  109.  
  110.                     Polyline(hdc, line, 2);
  111.                     line[0] = line[1];
  112.                     ReleaseDC(hdc);
  113.                 }
  114.             }
  115.         }
  116.         else
  117.         {
  118.             bThere = TRUE;
  119.         }
  120.     }
  121.     return 0;      
  122.  
  123.  
  124. STDMETHODIMP CSketcCtl::Erase()
  125. {
  126.     HDC hdc = GetDC();
  127.     Rectangle(hdc, left, top, right, bottom);
  128.     ReleaseDC(hdc);
  129.     return S_OK;
  130. }
  131.